#pragma once
#include<vector>



namespace wjx
{

	template<class T>
	class Less
	{
	public:
		bool operator()(const T& x, const T& y)
		{
			return x < y;
		}
	};

	template<class T>
	class Greater
	{
	public:
		bool operator()(const T& x, const T& y)
		{
			return x > y;
		}
	};
	template<class T, class Container = vector<T>,class Compare  = Less<T>>
	class priority_queue
	{
	public:
		void AdjustUP(int child)
		{
			Compare com;

			int parent = (child - 1) / 2;
			while (child > 0)
			{
				if (com(con[parent],con[child]))
				{
					swap(con[parent], con[child]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
				{
					break;
				}
			}
		}

		void push(const T& x )
		{
			con.push_back(x);
			AdjustUP(con.size() - 1);
		}
		void AdjustDown(int father)
		{
			int child = father * 2 + 1;
			Compare com;
			while (child < size())
			{
				if (child + 1 < con.size() && com(con[child], con[child + 1]))
				{
					child += 1;
				}
				if (com(con[father] , con[child]))
				{
					swap(con[father], con[child]);
					father = child;
					child = father * 2 + 1;
				}
				else
				{
					break;
				}
			}
		}
	void pop()
	{
		swap(con[0], con[size() - 1]);
		con.pop_back();
		AdjustDown(0);
	}
	const T& top()
	{
		return con[0];
	}

	int size()
	{
		return con.size();
	}
	bool empty()
	{
		return con.empty();
	}
private:
	Container con;
	};
	//
}